﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Staff_ConfirmPackage : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private vPackageDetail _package = new vPackageDetail();
    public vPackageDetail Package
    {
        get
        {
            return _package;
        }
        set
        {
            if (_package != value)
            {
                _package = value;
            }
        }
    }

    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        try
        {
            if (ViewState["packageid"] != null)
            {
                BLLConfirmShipment bll = new BLLConfirmShipment();
                string barcode = ViewState["barcode"].ToString();

                bll.confirmShipment((int)ViewState["packageid"], LoginedStaff.BranchID.Value);
                ViewState.Clear();

                string script = "window.open('ConfirmReceipt.aspx?barcode=" + barcode + "','_blank');window.location.reload();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newopen", script, true);

                // Server.Transfer("ConfirmReceipt.aspx?barcode=" + barcode, true);

                //Response.Redirect("ConfirmReceipt.aspx?barcode=" + ViewState["barcode"]);

                //Package = null;
                //Page.DataBind();
            }
        }
        catch
        {
            throw new Exception("Update encounter problem");
        }


    }


    protected void btnCheck_Click(object sender, EventArgs e)
    {
        txtBarcode_TextChanged(sender, e);
    }

    protected void txtBarcode_TextChanged(object sender, EventArgs e)
    {
        BLLConfirmShipment bll = new BLLConfirmShipment();
        string barcode = txtBarcode.Text.Replace("+","").Trim();
        if (!string.IsNullOrEmpty(barcode))
        {
            tblPackage package = bll.getPackageByBarcode(barcode);
            if (package != null)
            {
                ViewState["packageid"] = package.ID;
                ViewState["barcode"] = package.Barcode;
                Package = bll.getPackageInformation(package.ID);
                panelInfo.Visible = true;
                lblError.Text = "";
            }
            else
            {
                panelInfo.Visible = false;
                lblError.Text = "Barcode is not exist.";
            }
            txtBarcode.Text = "";
        }

        Page.DataBind();
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Package/EditPackage.aspx?barcode=" + ViewState["barcode"]);
    }
}